import Vue from "vue"
import VueRouter from "vue-router"
import store from "@/store"

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/home',
      name: 'Home',
      component: () => import(/* webpackChunkName: "base" */ '@/views/Home.vue')
    },
    {
      path: '/about',
      name: 'About',
      component: () => import(/* webpackChunkName: "base" */ '@/views/About.vue')
    },
    {
      path: '/getters',
      name: 'Getters',
      component: () => import(/* webpackChunkName: "base" */ '@/views/Getters.vue')
    },
  ]
})

// 全局路由守卫
router.beforeEach((to, from, next, x) => {
  // console.log("to ==> ", to)
  // console.log("from ==> ", from)
  // console.log("next ==> ", next)
  // console.log("x ==> ", x)
  
  store.dispatch("GET_USER_MENU")

  next()
})

export default router